﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Capstone_project.BussnessLogicLayer;
using Capstone_project.DatabaseAccessLayer;

namespace Capstone_project
{
    public partial class frmSearchTask : Form
    {

        SqlConnection con = Common.con;
        SqlDataAdapter adap;
        DataTable dt = new DataTable();
        ProjectBUS projectbus = new ProjectBUS();
        TaskGroupBUS taskgroupbus = new TaskGroupBUS();
        string sql = "SELECT USER_TASK.ID_TASK, TASK.NAME_TASK, PROJECT.NAME_PROJECT, TASK_GROUP.NAME_TASK_GROUP, PRIORITY.NAME_PRIORITY as Priority, TASK.TIMES, USER_TASK.START_DATE, USER_TASK.END_DATE, USER_TASK.USER_NAME, TASK.COMPLETE"
            + " FROM PRIORITY INNER JOIN (PROJECT INNER JOIN ((TASK_GROUP INNER JOIN TASK ON TASK_GROUP.ID_TASK_GROUP = TASK.ID_TASK_GROUP) INNER JOIN USER_TASK ON TASK.ID_TASK = USER_TASK.ID_TASK) ON PROJECT.ID_PROJECT = TASK_GROUP.ID_PROJECT) ON PRIORITY.ID_PRIORITY = TASK.ID_PRIORITY";

        public frmSearchTask()
        {
            InitializeComponent();
        }

        private void frmSearchTask_Load(object sender, EventArgs e)
        {
            if(con.State!=ConnectionState.Open)
                con.Open();
            SqlCommand com = new SqlCommand(sql,con);
            adap = new SqlDataAdapter(com);
            adap.Fill(dt);
            con.Close();
            dataGridView1.DataSource = dt.DefaultView;


            cbxProject.DataSource = projectbus.getList();
            cbxProject.ValueMember = "ID_PROJECT";
            cbxProject.DisplayMember = "NAME_PROJECT";
            cbxProject.SelectedValue = "";

            cbxGrouptask.DataSource = taskgroupbus.getList();
            cbxGrouptask.ValueMember = "ID_TASK_GROUP";
            cbxGrouptask.DisplayMember = "NAME_TASK_GROUP";
            cbxGrouptask.SelectedValue = "";
        }

        private void cbxProject_TextChanged(object sender, EventArgs e)
        {
            sql = "SELECT USER_TASK.ID_TASK, TASK.NAME_TASK, PROJECT.NAME_PROJECT, TASK_GROUP.NAME_TASK_GROUP, PRIORITY.LEVEL as Priority, TASK.TIME, USER_TASK.START_DATE, USER_TASK.END_DATE, USER_TASK.USER_NAME, TASK.COMPLETE"
            + " FROM PRIORITY INNER JOIN (PROJECT INNER JOIN ((TASK_GROUP INNER JOIN TASK ON TASK_GROUP.ID_TASK_GROUP = TASK.ID_TASK_GROUP) INNER JOIN USER_TASK ON TASK.ID_TASK = USER_TASK.ID_TASK) ON PROJECT.ID_PROJECT = TASK_GROUP.ID_PROJECT) ON PRIORITY.ID_PRIORITY = TASK.ID_PRIORITY WHERE (PROJECT.NAME_PROJECT ='"+cbxProject.Text+"')";
            
        }

        

        
    }
}
